// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   DBOpr.java

package com.vandagroup.common.treedic;

import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;

public class DBOpr
{

    private ResultSet rs;
    private Statement stm;
    private Connection conn;
    private HashMap keyValueMapping;

    public DBOpr()
    {
    }

    public void setConnection(Connection paConn)
    {
        conn = paConn;
    }

    public ArrayList query(String paSQL)
        throws SQLException
    {
        ArrayList value = new ArrayList();
        try
        {
            stm = conn.createStatement();
            rs = stm.executeQuery(paSQL);
            ResultSetMetaData rsmd = rs.getMetaData();
            int col = rsmd.getColumnCount();
            keyValueMapping = new HashMap();
            for(int i = 1; i <= col; i++)
                keyValueMapping.put(new Integer(i), rsmd.getColumnName(i));

            while(rs.next()) 
                if(col < 2)
                {
                    Object o = rs.getObject(1);
                    if(o == null)
                        value.add("");
                    else
                        value.add(o.toString().trim());
                } else
                {
                    ArrayList curvec = new ArrayList();
                    for(int i = 1; i <= col; i++)
                    {
                        Object o = rs.getObject(i);
                        if(o == null)
                            curvec.add("");
                        else
                            curvec.add(o.toString().trim());
                    }

                    value.add(curvec);
                }
            rs.close();
            stm.close();
        }
        catch(SQLException e)
        {
            throw e;
        }
        return value;
    }

    public int update(String paSQL)
        throws SQLException
    {
        int iRslt = 0;
        try
        {
            stm = conn.createStatement();
            iRslt = stm.executeUpdate(paSQL);
            stm.close();
        }
        catch(SQLException e)
        {
            throw e;
        }
        return iRslt;
    }

    public void commit()
        throws SQLException
    {
        conn.commit();
    }

    public void rollback()
        throws SQLException
    {
        conn.rollback();
    }

    public HashMap getKeyValueMapping()
    {
        return keyValueMapping;
    }

    public void setKeyValueMapping(HashMap keyValueMapping)
    {
        this.keyValueMapping = keyValueMapping;
    }
}
